$().ready(function() {	
	$.ajax({
		type: "get",
		url: "/xiaomi/user/valilogin",
		dataType: "json",
		success: function(data) {
			console.info(data);
			if(data.state == 0) {
				var menus = $(".fr>ul>li>a");
				var menu1 = menus[0];
				var menu2 = menus[1];
				$(menu1).attr("href", "javascript:void(0)").attr("id", "u-" + data.userid).text(data.username);
				$(menu2).attr("href", "javascript:void(0)").attr("id", "loginout").text("退出");
			}
		}
	});
	
	// 获取分类
	$.ajax({
		type: "get",
		url: "/xiaomi/product/clist",
		data: {
			"ctype": 1
		},
		dataType: "json",
		success: function(data) {
			if("SUCCESS" == data.msg) {
				for(var i = 0; i < data.data.length; i++) {
						var lis = $("#nav-1>ul>li");
						var category = data.data[i];
					for(var k = 0; k < lis.length; k++) {
						var li = lis[k].id.split("-")[1];
						if(li == category.category_id) {
							console.info(li + "=" + category.category_id);
							var cArray = category.page_title.split("/");
							var as = $("#nav-1>ul>li>a");
							for(var j = 0; j < cArray.length; j++) {
								if(lis[k].firstChild.nodeName=="a"){
									as[j].innerText = cArray[j];									
								}
							}
						}
					}
				}
			}
		}
	})
	// 获取产品
	var interval_5=$("#interval-5").attr("id");
	var interval=interval_5.split("-")[1];
	$.ajax({
		type: "get",
		url: "/xiaomi/product/plist",
		data: {
			"interval": interval
		},
		dataType: "json",
		success: function(data) {
			if("SUCCESS" == data.msg) {
				var $divs=$("#interval-5>div");
				for(var i = 0; i < data.data.length; i++) {
					var product=data.data[i];
					var $div=$divs[i];
					var id="p-data-"+(i+1);
					if($($div).attr("id")==id){
						id="#"+id;
						console.info($(id));
						var $sub_mingxing="<div class='sub_mingxing'><a href='./product/"+product.product_number+"'><img src='"+product.pic_img+"' alt=''></a></div>";
						var $pinpai="<div class='pinpai' id=p-'"+product.product_id+"'><a href='javascript:void(0)'>"+product.name+"</a></div>";
						var $youhui="<div class='youhui'>"+product.page_description+"</div>";
						var $jiage="<div class='jiage'>"+product.show_price+"元</div>";
						$(id).html($sub_mingxing+$pinpai+$youhui+$jiage);
					}
				}
			}
		}
	})
})